package com.it2297.renderer;

import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.it2297.model.Bid;

@SuppressWarnings("serial")
public class BiddersListCellRenderer extends JLabel implements ListCellRenderer
{
	private Bid bid;

	public BiddersListCellRenderer()
	{
		this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
	}

	@Override
	public Component getListCellRendererComponent(JList list, Object object, int index, boolean isSelected, boolean cellHasFocus)
	{
		bid = (Bid) object;

		// TODO BAD DESIGN, CALLING DATABASE IN FOLLOWING STATEMENT
		this.setText("<html><body>" + "<small>" + "<strong>" + bid.getNeedy().getNric() + " (" + bid.getNeedy().getName() + ") " + " [has won " + Bid.getWonBidNum(bid.getNeedy().getNric()) + " bid(s) previously]" + "</strong>" + "<br/>" + "Household Income: " + bid.getNeedy().getHouseHoldIncome() + "<br/>" + "No. of Dependant: " + bid.getNeedy().getNumOfDependent() + "<br/>" + "Family Size: " + bid.getNeedy().getFamilySize() + "<br/>" + "MPCI: " + (bid.getNeedy().getHouseHoldIncome() / bid.getNeedy().getFamilySize()) + "<br/>" + "Comment: " + bid.getComment() + "</small>" + "</body></html>");

		return this;
	}

}
